/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ProfileDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Profile;
import java.util.List;

/**
 *
 * @author eichawsan
 */
public class ProfileDAOImpl extends AbstractDAO implements ProfileDAO{

    public ProfileDAOImpl(){
        super();
    }
    @Override
    public Profile findProfile(String userName) throws HibernateAccessLayerException {
      try {
        //    // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Finding Profile" + ProfileName);
            Profile p = (Profile) super.find(Profile.class, userName);
            return p;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
    public List<Profile> findAllProfile() throws HibernateAccessLayerException {
        try {
            List result =  super.findAll(Profile.class);
            return (result);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
    
    @Override
    public void insertProfile(Profile profile) throws HibernateAccessLayerException {
        try {
          //  // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Inserting Profile" + profile.getUserName());
            super.saveOrUpdate(profile);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
    @Override
    public void updateProfile(Profile profile) throws HibernateAccessLayerException {
         try {
            // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Updating Profile" + profile.getUserName());
            super.saveOrUpdate(profile);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
    public void deleteProfile(Profile profile) throws HibernateAccessLayerException {
        try {
            // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Deleting Profile" + profile.getUserName());
            super.delete(profile);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Profile> findByCustomizeQuery(String queryString) throws HibernateAccessLayerException {
       try {  
         return (List<Profile>)this.findByCustomizeQuery(Profile.class,queryString);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    
    }
}
    
    

